package edu.gdin.ecommerce.util;

import java.util.Random;
import org.apache.commons.lang3.RandomStringUtils;

public class GenerateRandom {
	
	
	/**
	 * 生成固定位数的随机数字z
	 * @param len
	 * @return
	 */
	public static String randomStringNum(int len){
		return RandomStringUtils.random(len, false, true);
	}
	
	
	public static int Random(String star, String end) {

		int temp = 0;
		int a = Integer.parseInt(star);
		int b = Integer.parseInt(end);
		temp = a - b;
		double B = Math.random() * temp;
		int C = (int) B + b;
		return C;
	}

	public static String RandomPw() {
		Random r = new Random();
		Double d = r.nextDouble();
		String s = d + "";
		s = s.substring(3, 3 + 6);
		return s;
	}

	public static char getBankCardCheckCode(String nonCheckCodeCardId) {
		if (nonCheckCodeCardId == null
				|| nonCheckCodeCardId.trim().length() == 0
				|| !nonCheckCodeCardId.matches("\\d+")) {
			// 如果传的不是数据返回N
			return 'N';
		}
		char[] chs = nonCheckCodeCardId.trim().toCharArray();
		int luhmSum = 0;
		for (int i = chs.length - 1, j = 0; i >= 0; i--, j++) {
			int k = chs[i] - '0';
			if (j % 2 == 0) {
				k *= 2;
				k = k / 10 + k % 10;
			}
			luhmSum += k;
		}
		return (luhmSum % 10 == 0) ? '0' : (char) ((10 - luhmSum % 10) + '0');
	}
	
	public static void main(String[] args){
		String temp=GenerateRandom.randomStringNum(3);
		System.out.println(temp);
	}
}


